%	zhsusefulmacros.sty
%	This file provides several useful LaTeX macros as well as \ifLaTeX@e,
%	and \futurenonspacelet.
%	Licensed under LPPL.
\catcode`\@=11
\ifx\@usefulmacros@defined\@undefined\else
  \expandafter\endinput
\fi
\def\@usefulmacros@defined{\relax}
\def\@usefulmacros@LaTeX@e{LaTeX2e}
\def\ifLaTeX@e{\ifx\fmtname\@usefulmacros@LaTeX@e}
\ifLaTeX@e\else
\def\@nnil{\@nil}%
\def\@empty{}%
\def\@fornoop#1\@@#2#3{}%
\long\def\@for#1:=#2\do#3{%
  \expandafter\def\expandafter\@fortmp\expandafter{#2}%
  \ifx\@fortmp\@empty \else
    \expandafter\@forloop#2,\@nil,\@nil\@@#1{#3}\fi}%
\long\def\@forloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
       #5\def#4{#2}\ifx #4\@nnil \else#5\@iforloop #3\@@#4{#5}\fi\fi}%
\long\def\@iforloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
       \expandafter\@fornoop \else
      #4\relax\expandafter\@iforloop\fi#2\@@#3{#4}}%
\def\@tfor#1:={\@tf@r#1 }%
\long\def\@tf@r#1#2\do#3{\def\@fortmp{#2}\ifx\@fortmp\space\else
    \@tforloop#2\@nil\@nil\@@#1{#3}\fi}%
\long\def\@tforloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
       \expandafter\@fornoop \else
      #4\relax\expandafter\@tforloop\fi#2\@@#3{#4}}%
\long\def\@ifnextchar#1#2#3{%
  \let\reserved@d=#1%
  \def\reserved@a{#2}%
  \def\reserved@b{#3}%
  \futurelet\@let@token\@ifnch}
\def\@ifnch{%
  \ifx\@let@token\@sptoken
    \let\reserved@c\@xifnch
  \else
    \ifx\@let@token\reserved@d
      \let\reserved@c\reserved@a
    \else
      \let\reserved@c\reserved@b
    \fi
  \fi
  \reserved@c}
\def\:{\let\@sptoken= } \:  % this makes \@sptoken a space token
\def\:{\@xifnch} \expandafter\def\: {\futurelet\@let@token\@ifnch}
%
\long\def\@firstoftwo#1#2{#1}
\long\def\@secondoftwo#1#2{#2}
\expandafter\ifx\csname ifcsname\endcsname\relax
\def\@ifundefined#1{%
  \expandafter\ifx\csname#1\endcsname\relax
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\else
\def\@ifundefined#1{%
  \unless\ifcsname#1\endcsname
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\fi
%
\def\@namedef#1{\expandafter\def\csname #1\endcsname}
%
\fi % end of \ifLaTeX@e\else

\def\@BTcs{}
\let\nexttoken\relax
\let\next\relax
\def\futurenonspacelet#1{\def\@BTcs{#1}%
   \afterassignment\@BTfnslone\let\nexttoken= }
\def\@BTfnslone{\expandafter\futurelet\@BTcs\@BTfnsltwo}
\def\@BTfnsltwo{\expandafter\ifx\@BTcs\@sptoken\let\next=\@BTfnslthree
   \else\let\next=\nexttoken\fi \next}
\def\@BTfnslthree{\afterassignment\@BTfnslone\let\next= }

\ifx\fbox\@undefined
\newbox\fbox@tmpbox
\newdimen\fbox@linewidth
\newdimen\fbox@tmpdim
\fbox@linewidth=0.4pt
\long\def\fbox#1{%
  \setbox\fbox@tmpbox=\hbox{#1}%
  \fbox@tmpdim=2\fbox@linewidth
  \advance\fbox@tmpdim\wd\fbox@tmpbox
  \leavevmode\hbox{\vbox{\hrule height \fbox@linewidth width \fbox@tmpdim
  \hbox{\vrule width \fbox@linewidth height \ht\fbox@tmpbox
  #1\vrule width \fbox@linewidth height \ht\fbox@tmpbox}%
  \hrule height \fbox@linewidth width \fbox@tmpdim
  }}%
}
\fi
